package com.greatwqs.wmall.task.provider.scheduled;

import com.google.common.collect.Lists;
import com.greatwqs.wmall.common.module.util.JsonUtil;
import com.greatwqs.wmall.product.client.model.ProductResponse;
import com.greatwqs.wmall.product.client.service.ProductClientService;

import lombok.extern.slf4j.Slf4j;

import org.apache.dubbo.config.annotation.DubboReference;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

import java.util.List;
import java.util.concurrent.TimeUnit;

/**
 * @author wang-qingsong
 */
@Slf4j
@Component
public class ProductTestTask {

    @DubboReference
    private ProductClientService productClientService;

    @Scheduled(fixedDelay = 10, timeUnit = TimeUnit.SECONDS)
    public void productInfo() {
        ProductResponse response = productClientService.getProductById(1L);
        log.info("ProductTask getProductById(), response: {}", JsonUtil.toJson(response));

        List<ProductResponse> responses = productClientService.getProductListByIds(Lists.newArrayList(1L, 2L));
        log.info("ProductTask getProductListByIds(), response: {}", JsonUtil.toJson(responses));
    }
}
